#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"
void init_stack(ST* s1)
{
	assert(s1);
	s1->a = NULL;
	s1->capacity = 0;
	s1->top = 0;
}
void destroy_stack(ST* s1)
{
	assert(s1);
	free(s1->a);
	s1->a = NULL;
	s1->capacity = 0;
	s1->top = 0;
}
void stack_push(ST* s1, STDateType x)
{
	assert(s1);
	if (s1->top == s1->capacity)
	{
		int newcapacity = s1->capacity == 0 ? 4 : s1->capacity * 2;
		s1->a = (STDateType*)realloc(s1->a,sizeof(STDateType)*newcapacity);
		if (s1->a == NULL)
		{
			perror("stack_push");
			exit(-1);
		}
		s1->capacity = newcapacity;
	}
	s1->a[s1->top] = x;
	s1->top++;
}
STDateType stack_top(ST* s1)
{
	assert(s1);
	assert(s1->top>0);
	return s1->a[s1->top - 1];
}
void stack_pop(ST* s1)
{
	assert(s1);
	assert(s1->top > 0);
	s1->top--;
}
int stack_size(ST* s1)
{
	assert(s1);
	return s1->top;
}
bool stack_empty(ST*s1)
{
	assert(s1);
	return s1->top==0;
}